<?php
include '../database/koneksi/Koneksi.php';
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Search
 *
 * @author BAGUS
 */
class Search {

    //put your code here
    public function cariKlikKategori($id) {
        $koneksi = new Koneksi();
        $koneksi->koneksiDB();
        $rs = mysql_query("select * from barang where id_kategori='$id'");
        if (!$rs) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }
        return $rs;
    }

    public function namaKategori($id) {
        $nama = null;
        $koneksi = new Koneksi();
        $koneksi->koneksiDB();
        $rs = mysql_query("select * from kategori where id_kategori='$id'");
        if (!$rs) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }
        while ($row = mysql_fetch_array($rs)) {
            $nama = $row["nama_kategori"];
        }
        return $nama;
    }

    public function namaPemberi($id) {
        $nama = null;
        $koneksi = new Koneksi();
        $koneksi->koneksiDB();
        $rs = mysql_query("select * from pemberi where id_pemberi='$id'");
        if (!$rs) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }
        while ($row = mysql_fetch_array($rs)) {
            $nama = $row["nama_pemberi"];
        }
        return $nama;
    }

    public function lokasiPemberi($id) {
        $lokasi = null;
        $kab = null;
        $prov = null;
        $koneksi = new Koneksi();
        $koneksi->koneksiDB();
        $rs1 = mysql_query("select * from pemberi where id_pemberi='$id'");
        if (!$rs) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }
        while ($row1 = mysql_fetch_array($rs1)) {
            $lokasi = $row["id_kabupaten_pemberi"];
        }
        $rs2 = mysql_query("select * from kabupaten_pemberi where id_kabupaten_pemberi='$lokasi'");
        if (!$rs) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }
        while ($row2 = mysql_fetch_array($rs2)) {
            $kab = $row2["nama_kabupaten_pemberi"];
            $lokasi = $row2["id_propinsi_pemberi"];
        }
        $rs3 = mysql_query("select * from propinsi_pemberi where id_propinsi_pemberi='$lokasi'");
        if (!$rs) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }
        while ($row3 = mysql_fetch_array($rs3)) {
            $prov = $row3["nama_propinsi_pemberi"];
        }
        $lokasi = $kab . " - " . $prov;
        return $lokasi;
    }

}
